package com.cans.lightning.business.lowcode.web;

import com.cans.lightning.base.dto.ResDto;
import com.cans.lightning.business.lowcode.dto.AppFormRowDataDto;
import com.cans.lightning.business.lowcode.manager.form.bean.AppFormBean;
import com.cans.lightning.business.lowcode.service.api.IAppFormDataService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 表单数据运行接口
 *
 * @author shencan
 * @date 2020/6/14 22:14
 */
@RestController
@RequestMapping("/run/app_form")
public class AppFormDataController  {

    @Resource
    private IAppFormDataService appFormDataService;

    @PostMapping("/saveOrUpdate")
    public ResDto<String> saveOrUpdate(@RequestBody AppFormRowDataDto formDataDto){
        appFormDataService.saveOrUpdate(formDataDto);
        return ResDto.success();
    }

    @PostMapping("/createOrEdit")
    public ResDto<AppFormBean> createOrEdit(@RequestBody AppFormRowDataDto formDataDto){
        return ResDto.success(appFormDataService.createOrEdit(formDataDto));
    }

    @PostMapping("/deleteById")
    public ResDto<String> deleteById(@RequestBody AppFormRowDataDto formDataDto){
        appFormDataService.deleteById(formDataDto);
        return ResDto.success();
    }

    @PostMapping("/getPageData")
    public ResDto<List<Map>> getPageData(@RequestBody AppFormRowDataDto formDataDto){
        return ResDto.success(appFormDataService.getPageData(formDataDto));
    }
}
